
#include "ka-app/app.h"

using namespace ka;

IApplicationImpl::~IApplicationImpl() {
    /*nothing*/
}

const UUID Application::EVENT_UID("F982FF00-E9AF-9660-81A9-67B79C11C34B");

Application::Application()
: _impl(NULL),
_mfest(NULL) {
    _impl = getDefaultImpl();
}

Application::Application(IApplicationImpl *impl) 
: _impl(impl) {
}

void Application::setContextManifest(IContextManifest *mfest) {
    _mfest = mfest;
}

int Application::run(int argc, char *argv[]) {
    int r = 0;
    if (_impl != NULL) {
        
        Context *userCxt = NULL;
        if (_mfest) {
            userCxt = _mfest->createContext();
        }
        
        /*
        The implementation is responsible for 'pumping events' or looping
        or whatever it needs to do to raise the events that drive the
        application.
         */
        r = _impl->run(argc, argv);
        
        if (_mfest) {
            _mfest->destroyContext(userCxt);
        }
    }
    return r;
}